package freespiritsocial.io.user.ui.adapter

import androidx.core.view.isInvisible
import androidx.core.view.isVisible
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import freespiritsocial.io.user.R
import freespiritsocial.io.user.data.model.bean.NotificationPojo
import freespiritsocial.io.user.databinding.ItemNotificationBinding
import freespiritsocial.io.user.ext.circleImageUrl
import java.util.*

/**
 * 添加图片适配器
 */
class NotificationsAdapter(
    data: ArrayList<NotificationPojo> = arrayListOf(),
    layoutResIdRes: Int = R.layout.item_notification
):
    BaseQuickAdapter<NotificationPojo,BaseDataBindingHolder<ItemNotificationBinding>>(layoutResIdRes,data) {

    override fun convert(holder: BaseDataBindingHolder<ItemNotificationBinding>,item: NotificationPojo) = with(holder.dataBinding) {
        val avatarSize = item.userInfos?.size ?: 0
        if (avatarSize <= 1) {
            this?.ivAvatar?.isInvisible = false
            this?.ivAvatar1?.isVisible = false
            this?.ivAvatar2?.isVisible = false
        } else {
            this?.ivAvatar?.isInvisible = true
            this?.ivAvatar1?.isVisible = true
            this?.ivAvatar2?.isVisible = true
            this?.ivAvatar2?.circleImageUrl(item.userInfos?.get(1)?.userAvatar)
        }
        this?.data = item
    }
}